//
//  CMDBPushManager.swift
//  CMDB
//
//  Created by 王磊 on 17/4/5.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

class CMDBPushManager: NSObject {
    
    static let getInstance: CMDBPushManager = CMDBPushManager()
    
    private override init() {
        super.init()
        
    }
}
extension CMDBPushManager: CMDBPushManagerDelegate {
    func regApns() {
        // 请求授权 因为 以后都是 8.0以上了 10.0以上 貌似有些不同
        
        if #available(iOS 10.0, *) {
            
            
        } else {
            
            let type = UIUserNotificationType.Alert.rawValue | UIUserNotificationType.Badge.rawValue | UIUserNotificationType.Sound.rawValue
            
            let set = UIUserNotificationSettings(forTypes: UIUserNotificationType(rawValue: type), categories: nil)
            
            UIApplication.sharedApplication().registerUserNotificationSettings(set)
            // 需要通过设备UDID, 和app bundle id, 发送请求, 获取deviceToken
            UIApplication.sharedApplication().registerForRemoteNotifications()
        }
        
    }
    func handleApnsData(userInfo: [NSObject : AnyObject]?, fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
        if let _ = userInfo {
            
            completionHandler(.NewData)
            
        } else {
            
            completionHandler(.NoData)
        }
    }
}